跳到主要内容

底部导航 bottomNavigationBar

jj

import 'views/Index.dart';
import 'views/Me.dart';
import 'views/News.dart';
import 'views/Products.dart';

import 'package:flutter/material.dart';

class App extends StatefulWidget {
@override
_AppState createState() => _AppState();
}

class _AppState extends State<App> {
var _currentIndex = 0;

Index index;
Me me;
News news;
Products products;

currentPage() {
switch (_currentIndex) {
case 0:
if (index == null) {
index = Index();
}
return index;
case 1:
if (news == null) {
news = News();
}
return news;
case 2:
if (products == null) {
products = Products();
}
return products;
case 3:
if (me == null) {
me = Me();
}
return me;
}
}

Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('First Route'),
),
body: currentPage(),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
onTap: ((index) {
setState(() {
_currentIndex = index;
});
}),
items: [
BottomNavigationBarItem(
title: Text('shouye'), icon: Icon(Icons.home)),
BottomNavigationBarItem(
icon: Icon(Icons.search), title: Text('search'))
],
),
);
}
}